package com.example.repository;

import com.example.document.EsItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ItemRepository extends ElasticsearchRepository<EsItem,Long> {
    Page<EsItem> findByTitleAndBrand(String title, String brand, Pageable pageable);

    Page<EsItem> findByTitleOrBrand(String title, String brand, Pageable pageable);

    @Query("{\n" +
            "    \"multi_match\": {\n" +
            "      \"query\": \"?0\",\n" +
            "      \"fields\": [\"title\",\"brand\"]\n" +
            "    }\n" +
            "  }")
    Page<EsItem> findByPage(String word, Pageable pageable);
    @Query("{\n" +
            "    \"prefix\": {\n" +
            "      \"title\": {\n" +
            "        \"value\": \"?0\"\n" +
            "      }\n" +
            "    }\n" +
            "  }")
    Page<EsItem> findByPrefix(String word, Pageable pageable);

}
